﻿using HuaCheng.DataAccess;
using HuaCheng.CommonClass;
using System;
using System.Text;
using HuaCheng.Model;

namespace HuaCheng.Controller
{
    /// <summary>
    /// 单位定制controller
    /// </summary>
    public class UnitOrderControl
    {
        public static string path = DicHelper.RetrieveConfigPath();//获取配置文件路径
        /// <summary>
        /// 获取变量单位
        /// </summary>
        /// <returns></returns>
        public static UnitOrder GetUnit()
        {
            string[] variant = new string[] { "Voltage", "Current", "Cap", "Template", "Resistance", "Power", "Time", "Energy", "Pressure", "StepEditTime", "CommonShowTime" };//变量名称
            string[] units = new string[] { "V","A","Ah","℃","Ω","W","sec","Wh","kPa","hh:mm:ss:ms","hh:mm:ss"};//默认单位
            for (int i = 0; i < units.Length; i++)
            {
                StringBuilder temp = new StringBuilder(500);
                //根据配置文件读取showStatus
                int result = ReadAndWriteIni.GetPrivateProfileString("unit custom", variant[i], "", temp, 500, path);
                if (result > 0)//读取成功则传值，否则使用默认值
                {
                    units[i] = Convert.ToString(temp);
                }
            }
            UnitOrder uo = new UnitOrder()
            {
                Voltage = units[0],
                Current=units[1],
                Capacity=units[2],
                Template=units[3],
                Resistance=units[4],
                Power=units[5],
                Time=units[6],
                Energy =units[7],
                Pressure=units[8],
                StepEditTime=units[9],
                CommonShowTime=units[10]
            };
            return uo;
        }
    }
}
